//
//  XBridgeWebView.m
//  JSTest
//
//  Created by 奇林刘 on 2018/9/30.
//  Copyright © 2018年 奇林刘. All rights reserved.
//

#import "XBridgeWebView.h"
#import "XBridge.h"

@implementation XBridgeWebView

- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration {
    self = [super initWithFrame:frame configuration:configuration];
    if (self) {
        [self makeProgressView];
        [[XBridge shareXBridge] manageWebView:self];
    }
    return self;
}

- (void)dealloc {
    [[XBridge shareXBridge] abandonWebView:self];
}

- (WKNavigation *)loadRequest:(NSURLRequest *)request {
    [SVProgressHUD show];
    return [super loadRequest:request];
}

- (void)makeProgressView {
    self.progressView = [[UIProgressView alloc] init];
    self.progressView.progressTintColor = [UIColor greenColor];
    [self addSubview:self.progressView];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_safeAreaLayoutGuideTop);
        make.left.right.equalTo(self);
        make.height.equalTo(@(2));
    }];
}

@end
